package types

import (
	"cuelang.org/go/cue/ast"
	"fmt"
	"strings"
)

type Map struct {
	vv *ast.StructLit
}

func (t *Map) Value(ref bool) string {
	mType := t.vv.Elts[0].(*ast.Field).Label.(*ast.ListLit).Elts[0].(*ast.Ident).Name
	sType := t.vv.Elts[0].(*ast.Field).Value.(*ast.Ident).Name

	if strings.HasPrefix(sType, "#") {
		format := "map[%s]%s"
		if ref {
			format = "map[%s]*%s"
		}
		return fmt.Sprintf(format, mType, strings.TrimPrefix(sType, "#"))
	}
	return fmt.Sprintf("map[%s]%s", mType, sType)
}

func (t *Map) Default() string {
	return ""
}
